using Identity.Application.Contracts.Common;
using Identity.Application.Contracts.Services;
using Identity.Application.UserRoles.Commands;
using MediatR;

namespace Identity.Application.UserRoles.CommandHandlers;

public class GetUsersInRoleCommandHandler : IRequestHandler<GetUsersInRoleCommand, List<string>>
{

    private readonly IUserRoleService _userRoleService;

    public GetUsersInRoleCommandHandler(IUserRoleService userRoleService)
    {
        _userRoleService = userRoleService;
    }

    public async Task<List<string>> Handle(GetUsersInRoleCommand request, CancellationToken cancellationToken)
    {
        var users = await _userRoleService.GetUserRolesAsync(request.RoleId);
        if (users == null) return new List<string>();

        return users.ToList();
    }
}